package com.fr.chart.plot;

import com.fr.base.XMLable;
import com.fr.base.background.ColorBackground;
import com.fr.base.core.json.JSONException;
import com.fr.base.core.json.JSONObject;
import com.fr.base.xml.XMLPrintWriter;
import com.fr.base.xml.XMLReadable;
import com.fr.base.xml.XMLableReader;
import com.fr.chart.DataSeriesCondition;
import com.fr.chart.axis.SeriesAttrBackground;
import com.fr.chart.axis.SeriesAttrColor;
import com.fr.chart.axis.SeriesAttrLine;
import com.fr.chart.axis.SeriesAttrMarkerType;
import com.fr.chart.axis.SeriesAttrTrendLine;
import com.fr.chart.base.equals.Equals;
import com.fr.report.io.xml.ReportXMLUtils;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Set;

public class SeriesCollection
  implements XMLable
{
  private static final long serialVersionUID = 417500173279450632L;
  public static final String XML_TAG = "NewSeriesCollection";
  private Map seriesAttrMap = new HashMap();
  private SeriesAttr defaultSeriesAttr = new SeriesAttr();

  public void setSeriesAttrMap(Map paramMap)
  {
    this.seriesAttrMap = paramMap;
  }

  public Map getSeriesAttrMap()
  {
    return this.seriesAttrMap;
  }

  public void putSeriesAttr(int paramInt, SeriesAttr paramSeriesAttr)
  {
    getSeriesAttrMap().put(new Integer(paramInt), paramSeriesAttr);
  }

  public SeriesAttr getSeriesAttr(int paramInt)
  {
    if (getSeriesAttrMap().containsKey(new Integer(paramInt)))
      return ((SeriesAttr)getSeriesAttrMap().get(new Integer(paramInt)));
    return this.defaultSeriesAttr;
  }

  public SeriesAttr getDefaultSeriesAttr()
  {
    return this.defaultSeriesAttr;
  }

  public void setDefaultSeriesAttr(SeriesAttr paramSeriesAttr)
  {
    this.defaultSeriesAttr = paramSeriesAttr;
  }

  public DataSeriesCondition getSeriesCondition(DataSeriesCondition paramDataSeriesCondition, int paramInt)
  {
    Object localObject = getSeriesAttr(paramInt).isContains(paramDataSeriesCondition);
    if (localObject == null)
    {
      localObject = getDefaultSeriesAttr().isContains(paramDataSeriesCondition);
      if (localObject == null)
        if (paramDataSeriesCondition instanceof SeriesAttrColor)
        {
          localObject = new SeriesAttrColor(com.fr.chart.core.ChartCoreConstants.CHART_COLOR_ARRAY[paramInt]);
        }
        else if (paramDataSeriesCondition instanceof SeriesAttrBackground)
        {
          ColorBackground localColorBackground = ColorBackground.getInstance(com.fr.chart.core.ChartCoreConstants.CHART_COLOR_ARRAY[paramInt]);
          localObject = new SeriesAttrBackground(localColorBackground);
        }
        else if (paramDataSeriesCondition instanceof SeriesAttrLine)
        {
          localObject = new SeriesAttrLine(com.fr.chart.core.ChartCoreConstants.CHART_COLOR_ARRAY[paramInt], 1);
        }
        else if (paramDataSeriesCondition instanceof SeriesAttrMarkerType)
        {
          localObject = new SeriesAttrMarkerType(paramInt);
        }
        else if (paramDataSeriesCondition instanceof SeriesAttrTrendLine)
        {
          localObject = null;
        }
        else
        {
          return paramDataSeriesCondition;
        }
    }
    return ((DataSeriesCondition)localObject);
  }

  public void readXML(XMLableReader paramXMLableReader)
  {
    if (paramXMLableReader.isChildNode())
    {
      String str = paramXMLableReader.getTagName();
      if (str.equals("SeriesAttr"))
        this.defaultSeriesAttr = ((SeriesAttr)ReportXMLUtils.readXMLable(paramXMLableReader));
      else if (str.equals("SeriesAttrMap"))
        paramXMLableReader.readXMLObject(new XMLReadable(this)
        {
          private final SeriesCollection this$0;

          public void readXML()
          {
            if ("Entry".equals(paramXMLableReader.getTagName()))
            {
              String str;
              int i = -1;
              if ((str = paramXMLableReader.getAttr("index")) != null)
                i = Integer.parseInt(str);
              if (i != -1)
                paramXMLableReader.readXMLObject(new SeriesCollection.2(this, new Integer(i)));
            }
          }

          static SeriesCollection access$000(1 param1)
          {
            return param1.this$0;
          }
        });
    }
  }

  public void writeXML(XMLPrintWriter paramXMLPrintWriter)
  {
    paramXMLPrintWriter.startTAG("NewSeriesCollection");
    if (this.defaultSeriesAttr != null)
      ReportXMLUtils.writeXMLable(paramXMLPrintWriter, this.defaultSeriesAttr, "SeriesAttr");
    if ((this.seriesAttrMap != null) && (this.seriesAttrMap.size() > 0))
    {
      paramXMLPrintWriter.startTAG("SeriesAttrMap");
      Iterator localIterator = this.seriesAttrMap.entrySet().iterator();
      while (localIterator.hasNext())
      {
        Map.Entry localEntry = (Map.Entry)localIterator.next();
        int i = ((Integer)localEntry.getKey()).intValue();
        SeriesAttr localSeriesAttr = (SeriesAttr)localEntry.getValue();
        paramXMLPrintWriter.startTAG("Entry").attr("index", i);
        ReportXMLUtils.writeXMLable(paramXMLPrintWriter, localSeriesAttr, "SeriesAttr");
        paramXMLPrintWriter.end();
      }
      paramXMLPrintWriter.end();
    }
    paramXMLPrintWriter.end();
  }

  public Object clone()
    throws CloneNotSupportedException
  {
    SeriesCollection localSeriesCollection = (SeriesCollection)super.clone();
    if (this.defaultSeriesAttr != null)
      localSeriesCollection.defaultSeriesAttr = ((SeriesAttr)this.defaultSeriesAttr.clone());
    if (getSeriesAttrMap() != null)
    {
      localSeriesCollection.setSeriesAttrMap(new HashMap());
      Iterator localIterator = getSeriesAttrMap().entrySet().iterator();
      while (localIterator.hasNext())
      {
        Map.Entry localEntry = (Map.Entry)localIterator.next();
        localSeriesCollection.getSeriesAttrMap().put(localEntry.getKey(), localEntry.getValue());
      }
    }
    return localSeriesCollection;
  }

  public boolean equals(Object paramObject)
  {
    if (!(paramObject instanceof SeriesCollection))
      return false;
    SeriesCollection localSeriesCollection = (SeriesCollection)paramObject;
    if (!(Equals.equals(localSeriesCollection.defaultSeriesAttr, this.defaultSeriesAttr)))
      return false;
    if (localSeriesCollection.seriesAttrMap.size() != this.seriesAttrMap.size())
      return false;
    for (int i = 0; i < localSeriesCollection.seriesAttrMap.size(); ++i)
      if (!(Equals.equals(localSeriesCollection.getSeriesAttr(i), getSeriesAttr(i))))
        return false;
    return true;
  }

  public JSONObject toJSONObject()
    throws JSONException
  {
    JSONObject localJSONObject1 = new JSONObject();
    if ((this.seriesAttrMap != null) && (this.seriesAttrMap.size() > 0))
    {
      ArrayList localArrayList = new ArrayList();
      Set localSet = this.seriesAttrMap.entrySet();
      Iterator localIterator = localSet.iterator();
      while (localIterator.hasNext())
      {
        Map.Entry localEntry = (Map.Entry)localIterator.next();
        JSONObject localJSONObject2 = new JSONObject();
        localJSONObject2.put("key", localEntry.getKey());
        localJSONObject2.put("value", ((SeriesAttr)localEntry.getValue()).toJSONObject());
        localArrayList.add(localJSONObject2);
      }
      localJSONObject1.put("seriesAttrMap", localArrayList.toArray());
    }
    if (this.defaultSeriesAttr != null)
    {
      localJSONObject1.put("seriesAttrType", this.defaultSeriesAttr.getSeriesAttrType());
      localJSONObject1.put("defaultSeriesAttr", this.defaultSeriesAttr.toJSONObject());
    }
    return localJSONObject1;
  }

  static Map access$100(SeriesCollection paramSeriesCollection)
  {
    return paramSeriesCollection.seriesAttrMap;
  }
}